package com.huawei.appgallery.common.media.adapter;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.huawei.appgallery.common.media.api.OriginalMediaBean;
import com.huawei.appgallery.common.media.bean.SelectedMediaInfo;
import java.text.DecimalFormat;
import o.ble.b;
import o.ble.j;
import o.blj;
import o.blj.c;
import o.blu;

public class VideoThumbnailAdapter extends BaseThumbnailAdapter {
    private static final long CONSTANT_G = 1073741824;
    private static final long CONSTANT_K = 1024;
    private static final long CONSTANT_M = 1048576;
    private static final long VIDEO_MAX_SIZE = 37748736;
    private static final long VIDEO_MAX_SIZE_PARM = 36;

    static class a {
        private ImageView ˊ;
        private ImageView ˋ;
        private TextView ˎ;
        private ImageView ˏ;
        private ImageView ॱ;

        private a() {
        }
    }

    public VideoThumbnailAdapter(Context context) {
        super(context);
        this.mediaType = "video";
        this.selectMaxSize = 1;
    }

    private a createViewHolder(View view) {
        a aVar = new a();
        aVar.ˏ = (ImageView) view.findViewById(b.ͺ);
        aVar.ˊ = (ImageView) view.findViewById(b.ˋˊ);
        aVar.ॱ = (ImageView) view.findViewById(b.ˎˏ);
        aVar.ˎ = (TextView) view.findViewById(b.ॱͺ);
        aVar.ˋ = (ImageView) view.findViewById(b.ʽ);
        view.setTag(aVar);
        return aVar;
    }

    private void initViewHolder(a aVar) {
        aVar.ˊ.setVisibility(4);
        aVar.ˋ.setVisibility(4);
        aVar.ॱ.setVisibility(0);
        aVar.ˎ.setVisibility(0);
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        a createViewHolder;
        if (view == null) {
            view = this.inflater.inflate(j.ʽ, null);
            createViewHolder = createViewHolder(view);
        } else {
            createViewHolder = (a) view.getTag();
        }
        initViewHolder(createViewHolder);
        final OriginalMediaBean originalMediaBean = (OriginalMediaBean) this.originalBeanList.get(i);
        final int ᐝ = originalMediaBean.ᐝ();
        createViewHolder.ˎ.setText(getVideoTipInfo(originalMediaBean));
        if (!this.selectedMap.isEmpty() && this.selectedMap.containsKey(Integer.valueOf(ᐝ))) {
            createViewHolder.ˊ.setVisibility(0);
            createViewHolder.ॱ.setVisibility(4);
            createViewHolder.ˋ.setVisibility(0);
        }
        view.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ VideoThumbnailAdapter ˏ;

            public void onClick(View view) {
                a aVar = (a) view.getTag();
                if (this.ˏ.selectedMap.containsKey(Integer.valueOf(ᐝ))) {
                    aVar.ˊ.setVisibility(4);
                    aVar.ˋ.setVisibility(4);
                    aVar.ॱ.setVisibility(0);
                    int i = ((SelectedMediaInfo) this.ˏ.selectedMap.remove(Integer.valueOf(ᐝ))).ˏ;
                    if (i <= this.ˏ.selectedMap.size()) {
                        for (Integer num : this.ˏ.selectedMap.keySet()) {
                            SelectedMediaInfo selectedMediaInfo = (SelectedMediaInfo) this.ˏ.selectedMap.get(num);
                            if (selectedMediaInfo.ˏ > i) {
                                selectedMediaInfo.ˏ--;
                            }
                        }
                        this.ˏ.notifyDataSetChanged();
                    }
                } else if (this.ˏ.selectedMap.size() < this.ˏ.selectMaxSize && ((long) originalMediaBean.ʻ()) < VideoThumbnailAdapter.VIDEO_MAX_SIZE) {
                    aVar.ˊ.setVisibility(0);
                    aVar.ॱ.setVisibility(4);
                    SelectedMediaInfo selectedMediaInfo2 = new SelectedMediaInfo();
                    selectedMediaInfo2.ॱ = originalMediaBean;
                    selectedMediaInfo2.ˏ = this.ˏ.selectedMap.size() + 1;
                    selectedMediaInfo2.ˊ = this.ˏ.mediaType;
                    this.ˏ.selectedMap.put(Integer.valueOf(ᐝ), selectedMediaInfo2);
                    aVar.ˋ.setVisibility(0);
                }
                if (this.ˏ.iLoadImageListener != null) {
                    this.ˏ.iLoadImageListener.ˎ(this.ˏ.selectedMap.size());
                }
            }
        });
        loadImage(ᐝ, createViewHolder);
        return view;
    }

    private void loadImage(int i, a aVar) {
        c cVar = new c();
        cVar.ˋ(i);
        cVar.ॱ(true);
        cVar.ˎ(288);
        cVar.ˊ(288);
        cVar.ˎ(this.mediaType);
        blj.ˋ().ॱ(this.context, aVar.ˏ, cVar);
    }

    private String getVideoTipInfo(OriginalMediaBean originalMediaBean) {
        if (originalMediaBean == null) {
            return "";
        }
        return getVideoSize((long) originalMediaBean.ʻ()) + "  " + blu.ˎ((long) originalMediaBean.ʼ());
    }

    private String getVideoSize(long j) {
        float f;
        DecimalFormat decimalFormat = new DecimalFormat("###.##");
        String str = "B";
        if (j < 1024) {
            f = (float) j;
            str = "B";
        } else if (j < CONSTANT_M) {
            f = ((float) j) / 1024.0f;
            str = "CONSTANT_K";
        } else if (j < CONSTANT_G) {
            f = ((float) j) / 1048576.0f;
            str = "CONSTANT_M";
        } else {
            f = ((float) j) / 1.07374182E9f;
            str = "CONSTANT_G";
        }
        return decimalFormat.format(Float.valueOf(f)) + str;
    }
}
